package com.example.champtionthree.adapter;

import android.content.Context;
import android.os.Parcelable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.champtionthree.R;
import com.example.champtionthree.bean.ExamInfo;

import java.util.ArrayList;

public class FatherAdapter extends RecyclerView.Adapter<FatherAdapter.ViewHolder> {
    private  ArrayList<ExamInfo.SmallItemInfo> value;
    private Context mContext;

    public FatherAdapter( ArrayList<ExamInfo.SmallItemInfo> value, Context mContext) {
        this.value = value;
        this.mContext = mContext;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.father_adapter_layout,parent,false));
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
       if (position==0){
           holder.mRecyclerview.setLayoutManager(new GridLayoutManager(mContext,3));
           ArrayList<ExamInfo.SmallItemInfo> firstList=new ArrayList<>();
           for (int i = 0; i <6 ; i++) {
               firstList.add(value.get(i));
           }
           holder.mRecyclerview.setAdapter(new FirstChildAdapter(firstList,mContext));
       }else {
           holder.mRecyclerview.setLayoutManager(new LinearLayoutManager(mContext));
           ArrayList<ExamInfo.SmallItemInfo> firstList=new ArrayList<>();
           for (int i = 6; i <value.size() ; i++) {
               firstList.add(value.get(i));

           }
           holder.mRecyclerview.setAdapter(new SecondeAdapter(firstList,mContext));
       }

    }

    @Override
    public int getItemCount() {
        return 2;
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        RecyclerView mRecyclerview;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);

           mRecyclerview = itemView.findViewById(R.id.child_recyclervice);
        }
    }
}
